//
//  HOHeaderImgView.m
//  WeiDu_1_0
//
//  Created by foguo-mac-1 on 1/12/16.
//  Copyright © 2016 ShenOu. All rights reserved.
//

#import "HOHeaderImgView.h"
#import"SDWebImage/UIImageView+WebCache.h"
#import "HOImageMgr.h"
#import "HOUtils.h"

CGFloat kHeaderImgWidth = 60;
CGFloat kHeaderImgHeight = 60;

@interface HOHeaderImgView()
{
	UIImageView *headerImgView;
}

@end

@implementation HOHeaderImgView

- (id)init
{
	self = [super initWithFrame:CGRectMake(0,
										   0,
										   kHeaderImgWidth,
										   kHeaderImgHeight)];
	if(self)
	{
		[self setStyle];
		[self initViews];
	}
	return self;
}

- (id)initWithFrame:(CGRect)frame
{
	self = [super initWithFrame:frame];
	if(self)
	{
		[self setStyle];
		[self initViews];
	}
	return self;
	
}

- (void)setStyle
{
	self.layer.borderWidth = 2;
	self.layer.borderColor = [UIColor whiteColor].CGColor;
	self.layer.cornerRadius = self.frame.size.width / 2;
	[self.layer setMasksToBounds:YES];
}

- (void)initViews
{
	headerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0,
																 0,
																 self.frame.size.width,
																 self.frame.size.height)];
	headerImgView.contentMode = UIViewContentModeScaleAspectFit;
	[self addSubview:headerImgView];
}

- (void)setImageWithURL:(NSString *)url
{
	[headerImgView sd_setImageWithURL:[NSURL URLWithString:url]
					 placeholderImage:[[HOImageMgr sharedInstance] getDefaultImage]];
}

- (void)dealloc
{
	[HOUtils removeFromSuperViewForViews:headerImgView];
	[headerImgView removeFromSuperview];
	[headerImgView release];
	[super dealloc];
}

@end
